package com.csdj.web.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * packageName com.csdj.web.listener
 *
 * @author winver
 * @version 1.0
 * @className MySessionAttrListener
 * @date 2024/11/28
 * @description TODO
 */
@WebListener
public class MySessionAttrListener  implements HttpSessionAttributeListener {
    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        System.out.println("会话属性新增了=>" + se.getName() + ":" + se.getValue());
        if(se.getName().equals("name") && se.getValue().toString().contains("林")){
            System.out.println("万水青山就是金山银山");
        }
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        System.out.println("会话属性移除了=>" + se.getName() + ":" + se.getValue());
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        System.out.println("会话属性修改了=>" + se.getName() + ":旧值" + se.getValue()
                + ":新值:"+se.getSession().getAttribute(se.getName()));
        if(se.getName().equals("name") && se.getValue().toString().contains("林")){
            System.out.println("恢复了万水青山就是金山银山");
        }
    }
}
